package com.hifar.test.report.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hifar.fw.utils.lang.NumberUtils;
import com.hifar.fw.utils.lang.StringUtils;
import com.hifar.sys.*;
import com.hifar.test.report.pojo.HfEnvReportRecord;
import com.hifar.test.report.service.IHfEnvReportRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author maiti
 * @description 环境报告-流转记录
 * @date 2025/4/2 13:46
 */
@RestController
@RequestMapping("/api/busi/test/envReportRecord")
@Api("环境报告-流转记录")
public class HfEnvReportRecordController {

    @Autowired
    private IHfEnvReportRecordService reportRecordService;

    @PostMapping("/listPage")
    @ApiOperation("报告模块:列表查询[分页]")
    public BusiResponse listPage(@RequestBody Map<String, Object> queryParam) {
        int pageNo = NumberUtils.parseInt(queryParam.get("pageNo"), 1);
        int pageSize = NumberUtils.parseInt(queryParam.get("pageSize"), 20);
        String reportId = StringUtils.trimNull(queryParam.get("reportId"));
        QueryWrapper<HfEnvReportRecord> queryWrapper = RequestConver.getPostParam(queryParam);
        queryWrapper.in("secret_level", SystemLoginUser.dataSecretSet);
        queryWrapper.in("report_id", reportId);
        queryWrapper.orderByDesc("create_time");
        Page<HfEnvReportRecord> page = new Page<>(pageNo, pageSize);
        Page<HfEnvReportRecord> page1 = reportRecordService.page(page, queryWrapper);
        PageResult pageResult = SystemUtil.parsePage(page, page1);
        return BusiResponse.OK(pageResult);
    }

    @PostMapping("/list")
    @ApiOperation("报告模块:列表查询")
    public BusiResponse list(@RequestBody Map<String, Object> queryParam) {
        String reportId = StringUtils.trimNull(queryParam.get("reportId"));
        QueryWrapper<HfEnvReportRecord> queryWrapper = RequestConver.getPostParam(queryParam);
        queryWrapper.in("secret_level", SystemLoginUser.dataSecretSet);
        queryWrapper.in("report_id", reportId);
        queryWrapper.orderByDesc("create_time");
        List<HfEnvReportRecord> list = reportRecordService.list(queryWrapper);
        return BusiResponse.OK(list);
    }

}
